package com.app.demodata;

import cn.hutool.core.collection.CollectionUtil;
import com.app.config.AppRelaTopicProperties;
import com.app.mapper.BaseDataTestMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@SpringBootTest
@RunWith(SpringRunner.class)
public class CreateDemoData {

    @Autowired
    public BaseDataTestMapper baseDataTestMapper;

    @Autowired
    private AppRelaTopicProperties appRelaTopicProperties;

    @Test
    public void test() {
        Map<String, String> accessMapping = appRelaTopicProperties.getAccessMapping();
        Map<String, String> changeMapping = appRelaTopicProperties.getChangeMapping();
        System.out.println(accessMapping);
        System.out.println(changeMapping);
    }


    @Test
    public void createtable() {
        String tableName = "bigdata";
        List<String> fileds = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            fileds.add("filed" + i + " int");
        }
        String filedSql = CollectionUtil.join(fileds, ",");

        for (int i = 1; i < 101; i++) {
            final String tempTableName = tableName + i;
            baseDataTestMapper.executeCreateTableSql(tempTableName, filedSql);
        }

        for (int i = 1; i < 80; i++) {
            final String tempTableName = tableName + i;
            String sql = "INSERT INTO " + tempTableName + " (filed0, filed1, filed2, filed3, filed4, filed5, filed6, filed7, filed8, filed9, filed10, filed11, filed12, filed13, filed14, filed15, filed16, filed17, filed18, filed19, filed20, filed21, filed22, filed23, filed24, filed25, filed26, filed27, filed28, filed29, filed30, filed31, filed32, filed33, filed34, filed35, filed36, filed37, filed38, filed39, filed40, filed41, filed42, filed43, filed44, filed45, filed46, filed47, filed48, filed49, filed50, filed51, filed52, filed53, filed54, filed55, filed56, filed57, filed58, filed59, filed60, filed61, filed62, filed63, filed64, filed65, filed66, filed67, filed68, filed69, filed70, filed71, filed72, filed73, filed74, filed75, filed76, filed77, filed78, filed79, filed80, filed81, filed82, filed83, filed84, filed85, filed86, filed87, filed88, filed89, filed90, filed91, filed92, filed93, filed94, filed95, filed96, filed97, filed98, filed99) VALUES (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 11, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)";
            for (int j = 0; j < 1100; j++) {
                baseDataTestMapper.executeInsertSql(sql);
            }
        }

    }

    @Test
    public void createTableData() {
        String tableName = "bigdata";
        for (int i = 1; i < 80; i++) {
            final String tempTableName = tableName + i;
            String sql = "INSERT INTO " + tempTableName + " (filed0, filed1, filed2, filed3, filed4, filed5, filed6, filed7, filed8, filed9, filed10, filed11, filed12, filed13, filed14, filed15, filed16, filed17, filed18, filed19, filed20, filed21, filed22, filed23, filed24, filed25, filed26, filed27, filed28, filed29, filed30, filed31, filed32, filed33, filed34, filed35, filed36, filed37, filed38, filed39, filed40, filed41, filed42, filed43, filed44, filed45, filed46, filed47, filed48, filed49, filed50, filed51, filed52, filed53, filed54, filed55, filed56, filed57, filed58, filed59, filed60, filed61, filed62, filed63, filed64, filed65, filed66, filed67, filed68, filed69, filed70, filed71, filed72, filed73, filed74, filed75, filed76, filed77, filed78, filed79, filed80, filed81, filed82, filed83, filed84, filed85, filed86, filed87, filed88, filed89, filed90, filed91, filed92, filed93, filed94, filed95, filed96, filed97, filed98, filed99) VALUES (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 11, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)";
            for (int j = 1; j < 100; j++) {
                baseDataTestMapper.executeInsertSql(sql);
            }
        }
    }

}
